@include('admin.public.head')
<link href="{{ URL::asset('./admin/css/main.css') }}" rel="stylesheet">
<style>
html,body{
	height: auto !important;
	overflow: unset;
}
* {
    -webkit-box-sizing: initial;
    box-sizing: initial;
}
.checkbox {width:auto;margin-right: 4px !important;}
</style>
<body>
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
	<div class="fixed-bar">
		<div class="item-title">
			<!-- <a class="back" href="javascript:history.back();" title="返回列表">返回上一页</a> -->
			<div class="subject">
				<h3>角色名称 - 角色添加</h3>
				<h5>网站系统权限资源管理</h5>
			</div>
		</div>
	</div>
	<form class="form-horizontal" action="" id="roleform" method="post">
		<div class="ncap-form-default">
			<dl class="row">
				<dt class="tit">
					<label for="role_name"><em>*</em>角色名称</label>
				</dt>
				<dd class="opt">
					<input type="text" name="data[role_name]" id="role_name" value="" class="input-txt">
					<span class="err" id="name_err" style="display: none">导航名称不能为空!!</span>
					<p class="notic"></p>
				</dd>
			</dl>
			<dl class="row">
				<dt class="tit">
					<label for="role_desc"><em>*</em>角色描述</label>
				</dt>
				<dd class="opt">
					<textarea id="role_desc" name="data[role_desc]" class="tarea" rows="6"></textarea>
					<span class="err" id="err_tpl_content" style="display:none;">内容不能为空</span>
					<p class="notic"></p>
				</dd>
			</dl>

			<dl class="row">
				<dt class="tit">
					<label for="cls_full">权限分配</label>
				</dt>
				<dd style="margin-left:200px;">
					<div class="ncap-account-container" style="border-top:none;">
						<h4>
							<input id="cls_full" onclick="choosebox(this)" type="checkbox">
							<label>全选</label>
						</h4>
					</div>
					@foreach($modules as $kk=>$menu)
						<div class="ncap-account-container" style="border-top:none;">
							<h4>
								<label>{{$group[$kk]}}</label>
								<input value="1" cka="mod-{{$kk}}" type="checkbox">
								<label>全部</label>
							</h4>
							<ul class="ncap-account-container-list">
								@foreach($menu as $vv)
									<li>
										<label>
											<input type="checkbox" class="checkbox" name="right[]"  value="{{$vv->id}}" ck="mod-{{$kk}}" >{{$vv->name}}
										</label>
									</li>
								@endforeach
							</ul>
						</div>
					@endforeach
				</dd>
			</dl>

			<div class="bot"><a href="JavaScript:void(0);" onclick="roleSubmit();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a></div>
		</div>
		<!-- <if condition="192.168.1.1">
		<input type="hidden" name="role_id" value="192.168.1.1">
			</if> -->
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		$(":checkbox[cka]").click(function(){
			var $cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
			if($(this).is(':checked')){
				$cks.each(function(){$(this).prop("checked",true);});
			}else{
				$cks.each(function(){$(this).removeAttr('checked');});
			}
		});
	});

	function choosebox(o){
		var vt = $(o).is(':checked');
		if(vt){
			$('input[type=checkbox]').prop('checked',vt);
		}else{
			$('input[type=checkbox]').removeAttr('checked');
		}
	}

	function roleSubmit(){
		if($('#role_name').val() == '' ){
			layer.alert('角色名称不能为空', {icon: 2});
			return false;
		}


		var form = $("#roleform").serialize();

        $.ajax({
            url:"/add_role_do",    //请求的url地址
            dataType:"json",   //返回格式为json
            data:form,
            type:"POST",   //请求方式
            success:function(req){
                //请求成功时处理
                if(req.status == 0){
                    layer.msg(req.message);
                    return false;
                }

                layer.msg('操作成功！');
                setTimeout(function(){
                    window.location.href = "/role";
                },500);
            }
        });

        return false;
	}
</script>
</body>
</html>
